package com.smartx_newmobile;

import android.os.Bundle;

import com.facebook.react.ReactActivity;
// import com.facebook.react.NavigationActivity;

import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.DrawableImageViewTarget;

import android.view.View;
import android.app.Dialog;

public class MainActivity extends ReactActivity {
  private Dialog mSplashDialog;

  /**
   * Returns the name of the main component registered from JavaScript. This is used to schedule
   * rendering of the component.
   */
  @Override
  protected String getMainComponentName() {
    return "smartx_mobile";
  }

  @Override
  protected void onCreate(Bundle savedInstanceState) {
      loadLaunch();
      super.onCreate(savedInstanceState);

  }




  protected void loadLaunch(){
      // getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
      // WindowManager.LayoutParams.FLAG_FULLSCREEN);
      // hideNavigationBar();
      mSplashDialog = new Dialog(this,android.R.style.Theme_Black_NoTitleBar_Fullscreen);
      // mSplashDialog = new Dialog(this,R.style.SplashScreen_Fullscreen);
      // View dialogView = hideNavigationBar();
      mSplashDialog.setContentView(R.layout.launch_screen);
      // mSplashDialog.setContentView(dialogView);
      mSplashDialog.setCancelable(false);
      loadGIF();
  }

  //load GIF
  protected void loadGIF(){
    ImageView imageView = (ImageView) mSplashDialog.findViewById(R.id.launch_screen_gif);
    DrawableImageViewTarget imageViewTarget = new DrawableImageViewTarget(imageView);
    Glide.with(this).load(R.drawable.launch_screen_gif).into(imageViewTarget);
    mSplashDialog.show();
    imageView.postDelayed(new Runnable() {
      @Override
      public void run() {
        if (mSplashDialog.isShowing()) {
          mSplashDialog.dismiss();
         }
      }
  },3000);
  }

  @Override
  public void onWindowFocusChanged(boolean hasFocus) {
      super.onWindowFocusChanged(hasFocus);
//      if (hasFocus) {
//          hideNavigationBar();
//      }
  }

  private void hideNavigationBar() {
    View decorView = getWindow().getDecorView();

    int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
    decorView.setSystemUiVisibility(uiOptions);
}

  // private View hideNavigationBar() {

  //   int flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION//隐藏Navigation Bar
   
  //   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;//防止Navigation Bar在覆盖view的情况下上弹
   
  //   LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
   
  //   View view = inflater.inflate(R.layout.launch_screen, null);
   
  //   view.setOnTouchListener(new View.OnTouchListener() {
   
  //   @Override
   
  //   public boolean onTouch(View v, MotionEvent event) {
   
  //   return false;
   
  //   }
   
  //   });
   
  //   WindowManager windowManager = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
   
  //   int width = windowManager.getDefaultDisplay().getWidth();
  //   int height = windowManager.getDefaultDisplay().getHeight();

  //   WindowManager.LayoutParams params = new WindowManager.LayoutParams(width, height,
   
  //   WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
   
  //   WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, //让window占满整个手机屏幕，不留任何边界（border）
   
  //   PixelFormat.TRANSLUCENT);
   
  //   params.gravity = Gravity.TOP | Gravity.LEFT;
   
  //   params.y = 0;
   
  //   params.x = 0;
   
  //   windowManager.addView(view, params);
   
  //   view.setSystemUiVisibility(flags);

  //   return view;
   
  //   }
}
